﻿using Arnej.FriendFeed.Api;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System;
using System.Xml;
using System.Runtime.Serialization;
using System.IO;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Net;
using System.Linq;
using System.Linq.Expressions;

namespace Arnej.FriendFeed.Api.Test
{


    /// <summary>
    ///This is a test class for EntryTest and is intended
    ///to contain all EntryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class EntryTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion



        [TestMethod()]
        public void DeserializeTest()
        {
            Feed f = new Feed();
            Entry e = new Entry();
            e.Comments = new List<Comment>();
            e.Comments.Add(new Comment() { Body = "Blabla", User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }, Date = DateTime.Now });
            e.Comments.Add(new Comment() { Body = "Blabla", User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }, Date = DateTime.Now });
            e.Comments.Add(new Comment() { Body = "Blabla", User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }, Date = DateTime.Now });
            e.Comments.Add(new Comment() { Body = "Blabla", User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }, Date = DateTime.Now });
            e.Comments.Add(new Comment() { Body = "Blabla", User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }, Date = DateTime.Now });


            e.Hidden = "True";
            e.Id = Guid.NewGuid();
            e.Likes = new List<Like>();
            e.Likes.Add(new Like()
            {
                Date = DateTime.Now,
                User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }
            });
            e.Likes.Add(new Like()
            {
                Date = DateTime.Now,
                User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }
            });
            e.Likes.Add(new Like()
            {
                Date = DateTime.Now,
                User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }
            });
            e.Likes.Add(new Like()
            {
                Date = DateTime.Now,
                User = new User() { Id = Guid.NewGuid(), Name = "Arne", Nickname = "arnej", ProfileUri = "http://www.google.de" }
            });
            e.Link = "http://www.google.de";
            Thumbnail t = new Thumbnail();
            t.Height = 300;
            t.Width = 300;
            t.Url = "http://www.google.de";
            e.Media = new List<Media>();

            Media m = new Media();

            m.Thumbnails = new List<Thumbnail>();
            m.Thumbnails.Add(t);
            m.Thumbnails.Add(t);
            m.Thumbnails.Add(t);
            m.Thumbnails.Add(t);
            m.Thumbnails.Add(t);

            m.Contents = new List<Content>();

            Content c = new Content();

            c.Height = 300;
            c.MimeType = "flash";
            c.Url = "http://www.google.de";
            c.Width = 300;

            m.Contents.Add(c);
            m.Contents.Add(c);
            m.Contents.Add(c);
            m.Contents.Add(c);

            m.Player = "Flash";
            m.Title = "Titel";
            e.Media.Add(m);
            e.Media.Add(m);
            e.Media.Add(m);
            e.Media.Add(m);

            e.Published = DateTime.Now;
            e.Room = new Room()
            {
                Id = Guid.NewGuid(),
                Name = "Room",
                Nickname = "arnej",
                Url = "http://www.google.de"
            };
            e.Service = new Service()
            {
                IconUrl = "http://www.google.de",
                Id = Guid.NewGuid().ToString(),
                Name = "YouTube",
                ProfileUrl = "http://www.google.de"
            };
            e.Title = "Hallo Welt";
            e.Updated = DateTime.Now;
            e.User = new User()
            {
                Id = Guid.NewGuid(),
                Name = "arnej",
                Nickname = "Arne Janning",
                ProfileUri = "http://www.google.de"
            };
            e.Via = new Via()
            {
                Name = "Friendalizer",
                Url = "http://arnej.com"
            };

            //f.Entries = new Entry[] { e };
            f.Entries = new List<Entry>();
            f.Entries.Add(e);
            f.Entries.Add(e);
            f.Entries.Add(e);
            f.Entries.Add(e);
            f.Entries.Add(e);
            XmlSerializer s = new XmlSerializer(typeof(Feed));
            s.Serialize(new FileStream("C:\\test.xml", FileMode.OpenOrCreate), f);

            try
            {
                FileStream fs =
                new FileStream(@"C:\Users\Administrator\Desktop\Research\Arnej.FriendFeed.Api\ExampleFeed.xml",
                    FileMode.Open);

                XmlSerializer serializer = new XmlSerializer(typeof(Feed));


                Feed feed = serializer.Deserialize(fs) as Feed;

                Trace.WriteLine(feed.Entries.Count.ToString());

                //XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(
                //    fs, new XmlDictionaryReaderQuotas());

                //DataContractSerializer serializer = new DataContractSerializer(typeof(Feed));
                //Feed feed = serializer.ReadObject(reader, false) as Feed;
                //reader.Close();
                //fs.Close();

                //Trace.WriteLine(feed.Entries.Length.ToString());
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.InnerException.Message);

            }
        }



        [TestMethod]
        public void GetPublicFeedTest()
        {
            FriendFeedClient api = new FriendFeedClient("arnej", "creep584lain");
            Feed feed = api.GetPublicFeed();
            Debug.WriteLine(feed.Entries.Count.ToString());
        }

        [TestMethod]
        public void GetUsersFeedTest()
        {
            FriendFeedClient api = new FriendFeedClient("arnej", "creep584lain");
            User u = new User() { Nickname = "arnej" };
            List<User> list = new List<User>();
            list.Add(u);
            list.Add(u);

            list.Add(u);
            list.Add(u);
            list.Add(u);

            Feed f = api.GetMultipleUsersFeed(list, new Service() { Id = "twitter" });
            Debug.WriteLine(f.Entries.Count.ToString());
        }

        [TestMethod]
        public void GetUserCommentsTest()
        {
            FriendFeedClient api = new FriendFeedClient("arnej", "creep584lain");
            User u = new User() { Nickname = "scobleizer" };

            Feed f = api.GetUserComments(u, new Service() { Id = "twitter" });
            Debug.WriteLine(f.Entries.Count.ToString());
        }
    }
}
